var options = [
  ['语言', '主题色'],
  ['Language', 'Theme'],
], text = [
  { title: '设置', cancel: '取消', loading: '请稍候', succ: '修改成功' },
  { title: 'Options', cancel: 'Cancel', loading: 'Loading', succ: 'Modified'  },
];

var change = '',
  // lang = ['简体中文', 'English', '繁體中文', '한국어', '日本語'],
  lang = ['简体中文', 'English (Beta)'],
  color = { '#aaaffb': 'blue', '#fcc1d6': 'pink' };

Page({
  
  data: {
    showMask: true,
    showSheet: false,
    iconUrl: '/assets/module/',
    name: '',
  },

  onShow() {
    wx.onShow(this, text[wx.lang].title);
    this.setData({
      text: text[wx.lang],
      options: [
        { id: 0, title: options[wx.lang][0], label: lang[wx.lang] },
        { id: 1, title: options[wx.lang][1], label: color[wx.theme] },
      ]
    })
    // wx.getStorageSync(key)
    // wx.theme = wx.getStorageSync('theme') || '#aaaffb';

  },

  tap(e) {
    var sheetList = [];
    switch (e.currentTarget.id) {
      case '0':   // 点击了语言栏
        for (let i = 0; i < lang.length; ++i) 
          sheetList.push({ id: i, name: lang[i] });
        change = 'Language';
      break;
      case '1':   // 点击了主题色栏
        for (let i = 0; i < Object.keys(color).length; ++i)
          sheetList.push({ id: i, name: color[Object.keys(color)[i]] });
          console.log(sheetList)
        change = 'Theme';
      break;
    }
    this.setData({
      sheetList: sheetList,
      showSheet: true,
    })
  },

  onSelect(e) {
    console.log(e);
    switch (change) {
      case 'Language': 
        wx.showLoading({
          title: text[e.detail.id].loading,
          mask: true,
          success() {
            wx.lang = e.detail.id;
            wx.setStorageSync('language', e.detail.id);
            setTimeout(() => {
              wx.hideLoading();
              wx.reLaunch({
                url: '../../index/me/me',
              })
            }, 1000)
          }
        });
      break;
      case 'Theme': 
        let colorList = Object.keys(color);
        wx.theme = colorList[e.detail.id];
        wx.setStorageSync('theme', colorList[e.detail.id]);
        setTimeout(() => {
          wx.reLaunch({
            url: '../../index/me/me',
          })
          wx.toast(text[wx.lang].succ);
        }, 1000)
      break;
    
    }
  },

  onHide() {
    wx.onHide(this);
  },
  onClose() {
    this.setData({ showSheet: false });
  }
})